/* Copyright (c) 2004-2008, Andriy Nikolov
 * All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.processmining.email;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import com.borland.jbcl.layout.*;

/**
 * <p> A dialog to set the options for building a sociogram from the e-mail log.</p>
 * @author Andriy Nikolov
 * @version 1.0
 */

public class SociogramOptionsDialog extends JDialog {
  SociogramProducer sociogramProducer;
  JPanel panel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JPanel jPanelOptions = new JPanel();
  JPanel jPanelButtons = new JPanel();
  JButton jButtonOK = new JButton();
  JButton jButtonCancel = new JButton();
  ButtonGroup buttonGroupReplies = new ButtonGroup();
  VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JRadioButton jRadioButtonAll = new JRadioButton();
  JRadioButton jRadioButtonThreads = new JRadioButton();
  boolean ok;

  public SociogramOptionsDialog(Frame frame, SociogramProducer owner, String title, boolean modal) {
    super(frame, title, modal);
    sociogramProducer = owner;
    try {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }

  public SociogramOptionsDialog() {
    this(null, null, "", false);
  }
  void jbInit() throws Exception {
    panel1.setLayout(borderLayout1);
    jPanelButtons.setBorder(BorderFactory.createEtchedBorder());
    jPanelOptions.setBorder(BorderFactory.createEtchedBorder());
    jPanelOptions.setLayout(verticalFlowLayout1);
    jButtonOK.setPreferredSize(new Dimension(73, 27));
    jButtonOK.setText("OK");
    jButtonOK.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonOK_actionPerformed(e);
      }
    });
    jButtonCancel.setText("Cancel");
    jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonCancel_actionPerformed(e);
      }
    });
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setText("Do you want to count only message threads?");
    jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel2.setText("(reply messages will be excluded)");
    jRadioButtonAll.setHorizontalAlignment(SwingConstants.CENTER);
    jRadioButtonAll.setText("All messages");
    jRadioButtonThreads.setHorizontalAlignment(SwingConstants.CENTER);
    jRadioButtonThreads.setText("Only threads  ");
    getContentPane().add(panel1);
    panel1.add(jPanelOptions, BorderLayout.CENTER);
    panel1.add(jPanelButtons, BorderLayout.SOUTH);
    jPanelButtons.add(jButtonOK, null);
    jPanelButtons.add(jButtonCancel, null);
    jPanelOptions.add(jLabel1, null);
    jPanelOptions.add(jLabel2, null);
    jPanelOptions.add(jRadioButtonAll, null);
    jPanelOptions.add(jRadioButtonThreads, null);
    buttonGroupReplies.add(jRadioButtonAll);
    buttonGroupReplies.add(jRadioButtonThreads);
    buttonGroupReplies.setSelected(jRadioButtonAll.getModel(), true);
    ok = false;
  }

  public boolean isOK() {
    return ok;
  }

  void jButtonOK_actionPerformed(ActionEvent e) {
    sociogramProducer.setUseThreadsOnly(jRadioButtonThreads.isSelected());
    ok = true;
    processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }

  void jButtonCancel_actionPerformed(ActionEvent e) {
    ok = false;
    processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }
}
